import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/20 11:40
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.validPalindrome("abca");
    }

    public boolean validPalindrome(String s) {
        int n = s.length();
        int l = 0, r = n - 1;
        while (l < r) {
            char c1 = s.charAt(l), c2 = s.charAt(r);
            if (c1 == c2) {
                l++;
                r--;
            } else {
                return validPalindrome(s, l, r - 1) || validPalindrome(s, l + 1, r);
            }

        }
        return true;
    }

    public boolean validPalindrome(String s, int l, int r) {
        for (int i = l, j = r; i < j; i++, j--) {
            char c1 = s.charAt(i), c2 = s.charAt(j);
            if (c1 != c2) {
                return false;
            }
        }
        return true;
    }
}
